home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / namegram.zip / NEWPOS.FUN < prev    next >
Text File  |  1993-01-04  |  2KB  |  32 lines

  1.   FUNCTION NEW_POS(MyChar : char; VAR Str) :byte;
  2.       {----------------------------------------------------------------}
  3.       {  The TURBO "Pos" function is more complex than we need -- it   }
  4.       {  finds the position of a whole STRING within another STRING.   }
  5.       {  We just need to find one character within a STRING, as fast   }
  6.       {  as possible.  This routine, in 8088 assembler language, is    }
  7.       {  much faster.  Because I'm lazy, I took the easy way out to    }
  8.       {  give the function its returned value -- I assigned that value }
  9.       {  via a GLOBAL variable, "Make_It_Easy".  You'll have to either }
  10.       {  put that global variable into any program that uses this new  }
  11.       {  POS function, or rewrite the end of the INLINE code to do it  }
  12.       {  in a more elegant fashion.                                    }
  13.       {----------------------------------------------------------------}
  14.     BEGIN
  15.     Inline(
  16.       $FC/            {  CLD               ;forward direction}
  17.       $8A/$46/<MyChar/{  MOV AL,<MyChar[BP];character into AL}
  18.       $C4/$7E/<STR/   {  LES DI,<Str[BP]   ;load DI using ES  }
  19.       $31/$C9/        {  XOR CX,CX         ; clear out CX     }
  20.       $26/$8A/$0D/    {  MOV CL,ES:[DI]    ;load length       }
  21.       $89/$CA/        {  MOV DX,CX         ;save the length   }
  22.       $47/            {  INC DI                               }
  23.       $F2/$AE/        {  REPNE SCASB       ;Scan for char     }
  24.       $75/$02/        {  JNZ noChar                           }
  25.       $29/$D1/        {  SUB CX,DX         ;Take countdown    }
  26.                       {                    from original total}
  27.       $F7/$D9/        {  NEG CX                               }
  28.     {noChar:}
  29.       $88/$0E/Make_It_Easy);      {     Mov [<Make_It_Easy],CX}
  30.       New_Pos := Make_It_Easy;
  31.     end;
  32.